<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Model\User;
class UserController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        // 个人中心视图
        if(session('wechat.userid')){
            $list=\DB::table("admin_users")->where('id',session('wechat.userid'))->first();
            return view('user.index',['list'=>$list]);
        }else{
            return redirect(url('/'));
        }
        
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
    
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $list=json_decode($request['data']);
        $user=User::find($list->id);
        $user->username=$list->username;
        $user->sex=$list->sex;
        $user->minzu=$list->minzu;
        $user->phone=$list->phone;
        $user->sfz=$list->sfz;
        $user->address=$list->address;
        $user->lxr=$list->lxr;
        $user->lxrphone=$list->lxrphone;
        $user->address=$list->address;
        if($list->password!=$user->password){
            $user->password=bcrypt($list->password);
        }
        $user->beizhu=$list->beizhu;
        $success=$user->save();
        return json_encode($success);
        
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
